package Data_Flow;

import Data_IO.data_json.Json_CreditCardAccount;
import Data_IO.data_json.Json_MyFlight;
import Data_IO.data_json.Json_TargetFlight;
import Data_IO.data_json.Json_Traveller;
import org.junit.Test;

import java.io.IOException;

import static Data_IO.data_transformation.File2JsonArray.file2json;
import static Data_IO.data_transformation.JsonArray2file.json2file;

/**
 * The class which contains static methods of standardIO.
 *
 * @author Yibai Jiang
 * @author Shunhao Yan
 * @version 2.0
 * @since 27 April 2022
 */
public class DataStandardIO {

    /**
     * The instance of JSON format targetFlight objects
     */
    static Json_TargetFlight json_targetFlight;

    /**
     * The constant json_myFlight.
     */
    @Deprecated
    static Json_MyFlight json_myFlight;

    /**
     * The instance of JSON format traveller objects
     */
    static Json_Traveller json_traveller;

    /**
     * The instance of JSON format creditCardAccount objects
     */
    static Json_CreditCardAccount json_creditCardAccount;

    /**
     * Read traveller data form json file and save the data to the instance we created.
     *
     * @throws IOException the io exception
     */
    static public void readTraveller() throws IOException {
        json_traveller.syncJsonArray(file2json("./data/traveller.json"));
    }

    /**
     * Read targetFlight data form json file and save the data to the instance we created.
     *
     * @throws IOException the io exception
     */
    static public void readTargetFlight() throws IOException {
        json_targetFlight.syncJsonArray(file2json("./data/targetFlight.json"));
    }

    /**
     * Read creditCardAccount data form json file and save the data to the instance we created.
     *
     * @throws IOException the io exception
     */
    static public void readCreditCardAccount() throws IOException {
        json_creditCardAccount.syncJsonArray(file2json("./data/creditCardAccount.json"));
    }

    /**
     * Read my flight.
     *
     * @throws IOException the io exception
     */
    @Deprecated
    static public void readMyFlight() throws IOException {
        json_myFlight.syncJsonArray(file2json("./data/.json"));
    }

    /**
     * Initialize the json format instances.
     */
    static public void readInitialize(){
        DataStandardIO.json_targetFlight =  new Json_TargetFlight();
        DataStandardIO.json_creditCardAccount = new Json_CreditCardAccount();
        DataStandardIO.json_traveller = new Json_Traveller();
        DataStandardIO.json_myFlight = new Json_MyFlight();
    }

    /**
     * Upload the json format traveller data into corresponding json file.
     *
     * @throws IOException the io exception
     */
    static public void updateTraveller() throws IOException {
        json2file(json_traveller.getJsonarray(),"./data/traveller.json");
    }

    /**
     * Upload the json format targetFlight data into corresponding json file.
     *
     * @throws IOException the io exception
     */
    static public void updateTargetFlight() throws IOException {
        json2file(json_targetFlight.getJsonarray(),"./data/targetFlight.json");
    }

    /**
     * Upload the json format creditCardAccount data into corresponding json file.
     *
     * @throws IOException the io exception
     */
    static public void updateCreditCardAccount() throws IOException {
        json2file(json_creditCardAccount.getJsonarray(),"./data/creditCardAccount.json");
    }

    /**
     * Update my flight.
     *
     * @throws IOException the io exception
     */
    @Deprecated
    static public void updateMyFlight() throws IOException {
        json2file(json_myFlight.getJsonarray(),"./data/.json");
    }

}
